/*
 * @Descripttion: 
 * @version: 请写项目版本
 * @Author: @cdm
 * @Date: 2021-09-08 13:54:32
 * @LastEditors: @cdm
 * @LastEditTime: 2021-12-20 14:16:47
 * No pains no gains
 */
// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import { game } from "../../../../script/game/control/game";
import { carItem, itemType } from "../../../../script/game/gameType";
import { ListItem } from "../../../../script/util/ListView/ListItem";
import { ccs } from "../../../../script/util/services";
import { TouchExtend } from "../../../../script/util/TouchExd";
import { touchExd } from "../../../../script/util/TouchExtend";

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends ListItem<carItem> {
    carItem: carItem = null;
    initItem(data: carItem, index: number) {
        this.carItem = data;
        // ccs.spriteExd.setSprite(this.icon.node, ccs.resMgr.getItemIcon(data.icon));
        this.tips.string = data.desc;
        this.title.string = data.name;
        this.price.string = data.price.toString();
    }
    onItemclick(data: carItem) {
        cc.log(data);
        ccs.winMgr.showWin("popBuyItem", {id: data.id});
    }

    @property(cc.Label)
    title: cc.Label = null;

    @property(cc.Sprite)
    icon: cc.Sprite = null;

    @property(cc.Label)
    tips: cc.Label = null;

    @property(cc.Label)
    price: cc.Label = null;

    @property(cc.Node) 
    allBtn: cc.Node = null;

    @property(cc.Node) 
    monthBtn: cc.Node = null;

    start () {
        TouchExtend.touchEndScale(this.allBtn, () => {
            ccs.winMgr.showWin("popAlert", ({cb: this.buyAll}))
        })

        TouchExtend.touchEndScale(this.monthBtn, () => {
            ccs.winMgr.showWin("popBuyCar", { car: this.carItem});
        })
    }
    buyAll() {
        game.playerMgr.bag.assetsBag.addItem(this.carItem);
    }

}
